package com.xinxin.leetcode.problem804;

import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;

/**
 * @author ：史鑫鑫
 * @date ：Created in 2019/5/5 23:07
 */
class Solution {
    public int uniqueMorseRepresentations(String[] words) {
        String[] codes = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."};
        Set<String> set = new HashSet<>();
        for (String word : words) {
            StringBuilder res = new StringBuilder();
            for (int i = 0; i < word.length(); i++) {
                res.append(codes[word.charAt(i) - 'a']);
            }
            set.add(res.toString());
        }
        return set.size();
    }

    public static void main(String[] args) {
        String[] words = new String[]{"gin", "zen", "gig", "msg"};
        int res = new Solution().uniqueMorseRepresentations(words);
        System.out.println(res);
    }
}
